<?php
/**
 *
 */
class Sql {
    function __construct($argument) {
    }

    public function exec($ary_param, $ary_rep = null) {
        try {
            $file = parse_ini_file('./application/sql/'. $ary_param['file_name'], true);
            $sql = $file[$ary_param['key']];
            if (empty($ary_rep) == false) {
                foreach ($ary_rep as $key => $value) {
                    $sql = str_replace($key, $value, $sql);
                }
            }
            $this->load->database();
            $query = $this->db->query($sql, $ary_param['param']);
            $res = $query->result();
            return $res;
        } catch (Exception $e) {
            show_error('This page has error!! :)', $status_code = 500);
        }
    }

    public function update($ary_param, $ary_rep = null) {
        try {
            $file = parse_ini_file('./application/sql/'. $ary_param['file_name'], true);
            $sql = $file[$ary_param['key']];
            if (empty($ary_rep) == false) {
                foreach ($ary_rep as $key => $value) {
                    $sql = str_replace($key, $value, $sql);
                }
            }
            $this->load->database();
            $query = $this->db->query($sql, $ary_param['param']);
        } catch (Exception $e) {
            show_error('This page has error!! :)', $status_code = 500);
        }
    }
}

?>